﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace GTR.News.AdminDAL
{
    public class BackgroundUserDAL
    {
        /// <summary>
        /// 判断后台用户名和密码是否正确
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public int Login(string name,string pwd)
        {

            string sql1 = "select COUNT(*) from BackgroundUser where UserName='"+name+"'";

            if(Convert.ToInt32(DBhelper.Scalar(sql1))>0)
            {
                string sql = "select UserID,UserName,UserPwd,RoleID from BackgroundUser where UserName='" + name + "'";

                if(pwd==DBhelper.GetTable(sql).Rows[0][2].ToString())
                {
                    return 1;//登录成功
                }
                else
                {
                    return 2;//密码错误
                }
            }
            else
            {
                return 0;//该用户不存在
            }
        }
    }
}
